package com.atguigu.cloud.controller;
import com.atguigu.cloud.apis.PayFeignApi;
import com.atguigu.cloud.entities.PayDTO;
import com.atguigu.cloud.resp.ResultData;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
public class OrderController {
    @Resource
    private PayFeignApi payFeignApi;


    @PostMapping("/feign/pay/add")
    public ResultData addOrder(@RequestBody PayDTO payDTO){
        Integer orderCount = payDTO.getOrderCount();
        if (orderCount==null){
            payDTO.setOrderCount(1);
        }
        //1,增加订单号（+1）
        else {
            payDTO.setOrderCount(payDTO.getOrderCount() + 1);
        }
        //2，开启addPay支付微服务远程调用
        ResultData resultData = payFeignApi.addPay(payDTO);
        return resultData;
    }
    @GetMapping("/feign/pay/get/{id}")
    public ResultData getPayInfo(@PathVariable("id") Integer id){
        log.info("-------支付微服务远程调用，按照id查询订单支付流水信息");
        ResultData resultData = payFeignApi.getPay(id);
        return resultData;
    }
    /**
     * openfeign天然支持负载均衡演示
     *
     * @return
     */
    @GetMapping(value = "/feign/pay/mylb")
    public String mylb()
    {
        return payFeignApi.mylb();
    }
}
